package com.xy.simplefactory.pizzastore.order;


import com.xy.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/10 9:04
 * @description
 */
public class OrderPizza {

    private Pizza pizza = null;

    /**
     * 点餐
     */
    public OrderPizza() {
        String orderType = "";
        do {
            orderType = getType();
            pizza = PizzaSimpleFactory.createPizza(orderType);
            if (this.pizza != null) {
                // 输出制作
                this.pizza.prepare();
                this.pizza.bake();
                this.pizza.cut();
                this.pizza.box();
            } else {
                System.out.println("取消订购");
                break;
            }
        } while (true);
    }


    /**
     * 工具类选择披萨类型
     *
     * @return
     */
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("========披萨订购系统=========");
            System.out.println("1:希腊披萨 2:奶酪披萨 其他:退出");
            System.out.print("请选择:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
